﻿
//=======================================================================================================
function goto_page_onclick(p_button,p_fuseaction,p_direction_obj,p_exception_qa_obj,p_top_obj,p_bottom_obj) {
	if (p_button==1) {
		p_direction_obj.value = "TOP";
		p_exception_qa_obj.value = 0;
	}	
	if (p_button==2) {
		if (p_top_obj.value > 0) {
			p_direction_obj.value = "PREVIOUS";
		}else{
			return;
		}
		p_exception_qa_obj.value = p_top_obj.value;
	}	
	if (p_button==3) {
		if (p_bottom_obj.value > 0) {
			p_direction_obj.value = "NEXT";
		}else{
			return ;
		}
		p_exception_qa_obj.value = p_bottom_obj.value;
	}	
	if (p_button==4) {
		p_direction_obj.value = "BOTTOM";
		p_exception_qa_obj.value = 0;
	}	
	document.forms(0).fuseaction.value = p_fuseaction;
	document.forms(0).submit();
	return;
} 
//===================================================================================================
function close_none_submit(p_hdn_obj) {
	if (p_hdn_obj.value != ""){
		document.forms(0).submit();
	}
}
//===================================================================================================
function btn_approve_onclick(p_checkbox_obj,p_hidden_status,p_hidden_obj,p_fuseaction) {
	var list = checkbox_value_to_list(p_checkbox_obj,",");
	if (list) {   //Kiem tra xem co cau hoi nao duoc chon hay khong?
		if(list_count_element(list,",")==1)	{  //Kiem tra xem co phai chon 1 cau hoi hay khong?
			if (!p_checkbox_obj.length){
				if (p_hidden_status.value != 0) {
					p_hidden_obj.value = p_checkbox_obj.value;
					document.forms(0).fuseaction.value = p_fuseaction;
					document.forms(0).submit(); 	
				} else {
					alert("Câu hỏi này chưa có câu trả lời");
					return;
				}
			} else {
				for(i=0;i<p_checkbox_obj.length;i++){
					if (p_checkbox_obj[i].checked){
						if (p_hidden_status[i].value != 0) {
							p_hidden_obj.value = p_checkbox_obj[i].value;
							document.forms(0).fuseaction.value = p_fuseaction;
							document.forms(0).submit(); 	
						} else {
                                                        alert("Câu hỏi này chưa có câu trả lời");
							return;
						}
					}
				}
			}
		} else  {
			alert("Bạn chỉ được chọn một câu hỏi để kiểm duyệt");
			return;
		}
	} else {
		alert("Chưa có câu hỏi nào được chọn");
		return;		
	}
}
//===================================================================================================
function list_count_element(the_list,the_separator)
{	
	if (the_list=="") return -1;
	arr_value = the_list.split(the_separator);
	if (arr_value.length > 0){
			return arr_value.length;
	}
	return -1;
}	
//===================================================================================================
function rad_accept_onclick(){
	if (document.all.rad_accept[0].checked == true){
		document.forms(0).hdn_qa_status.value = 2;		
	}else {		
		document.forms(0).hdn_qa_status.value = 1;	
	}
}
//===================================================================================================
function onegate_qa_update_onclick(fuseaction){
	//replaceSource();
	//getContent();	
	btn_save_onclick_qa(fuseaction);
}
//===================================================================================================
function sel_change_onclick(p_select_obj,p_hidden_obj) {
	p_hidden_obj.value = p_select_obj.value ;
	document.forms(0).submit();
}
//===================================================================================================
function sel_onclick(p_select_obj,p_hidden_obj) {
	p_hidden_obj.value = p_select_obj.value ;
}
//===================================================================================================
// ham btn_save_onclick_qa() duoc goi khi NSD nhan chuot vao nut "Chap nhan"
//  - p_fuseaction: ten fuseaction tiep theo
function btn_save_onclick_qa(p_fuseaction,obj){
	document.f_dsp_single_qa_question_for_sending.hdn_fusecaction.value = p_fuseaction;//set fuseaction
	//alert('www'+f_dsp_single_qa_question_for_sending.hdn_fusecaction.value);
	if (_MODAL_DIALOG_MODE==1)
		document.f_dsp_single_qa_question_for_sending.action = "index.php?modal_dialog_mode=1";
	else
		document.f_dsp_single_qa_question_for_sending.action = "index.php";

	if (verify(document.f_dsp_single_qa_question_for_sending)){
		document.f_dsp_single_qa_question_for_sending.fuseaction.value = p_fuseaction;		
		document.f_dsp_single_qa_question_for_sending.submit();
	}	
}

function show_qa_by_agency(){
	var f = document.frm_dsp_all_qa_by_agency;
	var j_agency_id = f.sel_agency.value;
	f.agency_id.value = j_agency_id;
	var str_fuseaction = 'DISPLAY_ALL_QA_QUESTION_BY_AGENCY';
	f.fuseaction.value=str_fuseaction;
	f.submit();
}

function show_qa_by_cate(){
	var f = document.frm_dsp_all_qa_by_cate;
	var j_cate_id = f.sel_cate.value;
	f.cate_id.value = j_cate_id;
	var str_fuseaction = 'DISPLAY_ALL_QA_QUESTION_BY_CATE';
	f.fuseaction.value=str_fuseaction;
	f.submit();
}

function sel_onclick_qa(p_hidden_obj,p_select_obj) {
	p_hidden_obj.value = p_select_obj.value;
}
function delete_row_qa(p_row_obj, p_checkbox_obj, p_hdn_obj){
// Luu ID cua cac doi tuong bi xoa vao p_hdn_obj
if (checkbox_value_to_list(p_checkbox_obj,",")!=""){
	if (p_hdn_obj.value!=""){
		p_hdn_obj.value = p_hdn_obj.value + "," + checkbox_value_to_list(p_checkbox_obj,",");
		//alert('aa'+p_hdn_obj.value);
	}else{
		p_hdn_obj.value = checkbox_value_to_list(p_checkbox_obj,",");
	}
}
try{
	if (p_row_obj.length){
		for (i=0; i<p_row_obj.length; i++){
			if (p_checkbox_obj[i].checked){
				p_row_obj[i].style.display="none";
				p_checkbox_obj[i].checked=false;
			}
		}
	}
	else{
		if (p_checkbox_obj.checked){
			p_row_obj.style.display="none";
			p_checkbox_obj.checked=false;
		}
	}
}
catch(e){;}
}
function show_page_cate_by_agency(){
	var f = document.frm_dsp_all_cate_by_agency;
	var j_agency_id = f.sel_agency.value;
	f.agency_id.value=j_agency_id;
	var str_fuseaction = 'DISPLAY_ALL_CATE_BY_AGENCY';
	f.fuseaction.value=str_fuseaction;
	f.submit();
}
function show_page_agency_by_cate(){
	var f = document.frm_dsp_all_agency_by_cate;
	var j_cate_id = f.sel_cate.value;
	f.cate_id.value=j_cate_id;
	var str_fuseaction = 'DISPLAY_ALL_AGENCY_BY_CATE';
	f.fuseaction.value=str_fuseaction;
	f.submit();
}
function txt_search_qa_keypress(f,p_fuseaction){
	key = event.keyCode;
	if (key==13){
		btn_search_qa_onclick();
	}	
}